function [ PrimeArray ] = findPrimes(N)
%findPrimes Find the first N prime numbers
% [ PrimeArray ] = findPrimes(N)
% INPUT
%   N: Number of primes to find
% OUTPUT
%   PrimeArray: 1xN Array of prime numbers
%
% Example:
%   [ PrimeArray ] = findPrimes(10)

Cnt=0; %Number we have found so far in the loop
CurrentNum=2 %Our starting number (primes are >1)
PrimeArray=[] %This is where we will store the results
% The '[]' means an empty array.

while Cnt<N %Keep going until we find N primes
    FoundDivisor=0 % We will count the number of Divisors we find
    for nn=2:sqrt(CurrentNum) % Check numbers that could be Divisors
        FoundDivisor=FoundDivisor+(mod(CurrentNum,nn)==0)
        %Note the parenthesis for order of operation!
    end
    
    if FoundDivisor==0 %There were no divisors, so a prime
        Cnt=Cnt+1; %Increment the number we found
        PrimeArray(Cnt)=CurrentNum % Write the number under test into array
    end
    CurrentNum=CurrentNum+1; %Increment to try the next highest integer
    
end
end
